﻿using System;
using System.Net.Sockets;
using System.Text;
using HslCommunication.BasicFramework;

namespace HslCommunication.Core.Net
{
	/// <summary>
	/// 异形客户端的连接对象
	/// </summary>
	// Token: 0x02000144 RID: 324
	public class AlienSession
	{
		/// <summary>
		/// 实例化一个默认的参数
		/// </summary>
		// Token: 0x06001C5D RID: 7261 RVA: 0x0008C725 File Offset: 0x0008A925
		public AlienSession()
		{
			this.IsStatusOk = true;
			this.OnlineTime = DateTime.Now;
			this.OfflineTime = DateTime.MinValue;
		}

		/// <summary>
		/// 网络套接字
		/// </summary>
		// Token: 0x17000587 RID: 1415
		// (get) Token: 0x06001C5E RID: 7262 RVA: 0x0008C74F File Offset: 0x0008A94F
		// (set) Token: 0x06001C5F RID: 7263 RVA: 0x0008C757 File Offset: 0x0008A957
		public Socket Socket { get; set; }

		/// <summary>
		/// 唯一的标识
		/// </summary>
		// Token: 0x17000588 RID: 1416
		// (get) Token: 0x06001C60 RID: 7264 RVA: 0x0008C760 File Offset: 0x0008A960
		// (set) Token: 0x06001C61 RID: 7265 RVA: 0x0008C768 File Offset: 0x0008A968
		public string DTU { get; set; }

		/// <summary>
		/// 密码信息
		/// </summary>
		// Token: 0x17000589 RID: 1417
		// (get) Token: 0x06001C62 RID: 7266 RVA: 0x0008C771 File Offset: 0x0008A971
		// (set) Token: 0x06001C63 RID: 7267 RVA: 0x0008C779 File Offset: 0x0008A979
		public string Pwd { get; set; }

		/// <summary>
		/// 指示当前的网络状态
		/// </summary>
		// Token: 0x1700058A RID: 1418
		// (get) Token: 0x06001C64 RID: 7268 RVA: 0x0008C782 File Offset: 0x0008A982
		// (set) Token: 0x06001C65 RID: 7269 RVA: 0x0008C78A File Offset: 0x0008A98A
		public bool IsStatusOk { get; set; }

		/// <summary>
		/// 上线时间
		/// </summary>
		// Token: 0x1700058B RID: 1419
		// (get) Token: 0x06001C66 RID: 7270 RVA: 0x0008C793 File Offset: 0x0008A993
		// (set) Token: 0x06001C67 RID: 7271 RVA: 0x0008C79B File Offset: 0x0008A99B
		public DateTime OnlineTime { get; set; }

		/// <summary>
		/// 最后一次下线的时间
		/// </summary>
		// Token: 0x1700058C RID: 1420
		// (get) Token: 0x06001C68 RID: 7272 RVA: 0x0008C7A4 File Offset: 0x0008A9A4
		// (set) Token: 0x06001C69 RID: 7273 RVA: 0x0008C7AC File Offset: 0x0008A9AC
		public DateTime OfflineTime { get; set; }

		/// <summary>
		/// 进行下线操作
		/// </summary>
		// Token: 0x06001C6A RID: 7274 RVA: 0x0008C7B8 File Offset: 0x0008A9B8
		public void Offline()
		{
			bool isStatusOk = this.IsStatusOk;
			if (isStatusOk)
			{
				this.IsStatusOk = false;
				this.OfflineTime = DateTime.Now;
			}
		}

		/// <inheritdoc />
		// Token: 0x06001C6B RID: 7275 RVA: 0x0008C7E8 File Offset: 0x0008A9E8
		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(string.Concat(new string[]
			{
				"DtuSession[",
				this.DTU,
				"] [",
				this.IsStatusOk ? "Online" : "Offline",
				"]"
			}));
			bool isStatusOk = this.IsStatusOk;
			if (isStatusOk)
			{
				stringBuilder.Append(" [" + SoftBasic.GetTimeSpanDescription(DateTime.Now - this.OnlineTime) + "]");
			}
			else
			{
				bool flag = this.OfflineTime == DateTime.MinValue;
				if (flag)
				{
					stringBuilder.Append(" [----]");
				}
				else
				{
					stringBuilder.Append(" [" + SoftBasic.GetTimeSpanDescription(DateTime.Now - this.OfflineTime) + "]");
				}
			}
			return stringBuilder.ToString();
		}
	}
}
